package dailytest;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

import java.util.Objects;

/**
 * @author: heweiwei
 * @Date: 2022/8/11 21:11
 * @Desc:
 */
public class ZcTest {

    public static void main(String[] args) {

        JSONObject jsonObject=new JSONObject();

        String str = "$r.body.content";
        str = str.substring("$r.".length());
        System.out.println("str = " + str);
        String[] keys = str.split("\\.");

        JSON result = null;
        for (String key : keys) {
            result = getJsonObject(jsonObject, key);
            if (Objects.isNull(jsonObject)) {
                break;
            }
        }
        if (Objects.isNull(result)) {
            return;
        }

    }
    private static JSON getJsonObject(JSONObject jsonObject, String key) {
        if (Objects.nonNull(jsonObject) && Objects.nonNull(jsonObject.get(key))) {
            try {
                return (JSON) jsonObject.get(key);
            } catch (Exception e) {
                return null;
            }
        }
        return null;
    }
}
